#include "mat_game.h"

	//struct AnimateBoard
	//{
	//	void			Hide();
	//	void			Show();
	//	void			Tick(float dt);

	//	float			m_Delay;
	//	bool			m_IsFinish;
	//	math::Vec2		m_Offset;
	//	math::Vec2		m_Target;
	//};

MATGame::AnimateBoard::AnimateBoard() :	m_State(BOARD_STATE_HIDE),
										m_Accel(0),
										m_Delay(0),
										m_Offset(math::Vec2(0,-1.0f))
{
	
}

void	MATGame::AnimateBoard::Show(float Delay)
{
	if(m_State == BOARD_STATE_SHOW)
		return;
	if(m_State == BOARD_STATE_SHOWING)
		return;

	m_State = BOARD_STATE_SHOWING;
	m_Accel = 4.0f;
	m_Delay = Delay;
}

void	MATGame::AnimateBoard::Reset()
{
	m_Offset = math::Vec2(0,-1.0f);
	m_State = BOARD_STATE_HIDE;
}


void	MATGame::AnimateBoard::Hide(float Delay)
{
	if(m_State == BOARD_STATE_HIDE)
		return;
	if(m_State == BOARD_STATE_HIDING)
		return;

	m_State = BOARD_STATE_HIDING;
	m_Accel = 0.5f;
	m_Delay = Delay;
	
}

void	MATGame::AnimateBoard::Tick(float dt)
{
	if(m_Delay > 0)
	{
		m_Delay -= dt;
		return;
	}

	switch(m_State)
	{
	case BOARD_STATE_SHOWING:
			m_Accel -= dt;
			if(m_Accel <= 0.5f)
				m_Accel = 0.5f;
			m_Offset.y += (m_Accel * dt);
			if(m_Offset.y > 0)
			{
				m_State = BOARD_STATE_SHOW;
				m_Offset.y = 0;
			}
		break;


	case BOARD_STATE_HIDING:
			m_Accel += ( dt * 7.0f);
			//if(m_Accel > 1.0f)
			//	m_Accel = 1.0f;
			m_Offset.y -= (m_Accel * dt);
			if(m_Offset.y < -1.0f)
			{
				m_State = BOARD_STATE_HIDE;
				m_Offset.y = -1.0f;
			}
		break;
	}
}

